package com.orangelife.redis.core.redis.session.redisSession;

import java.util.Map;

import com.orangelife.redis.core.redis.RedisClient;
import com.orangelife.utils.ProConfig;

public class WebServiceSession {

	private String key;
	private RedisClient rc;
	private int expireSeconds = Integer.parseInt(ProConfig
			.getProValues("expireSeconds"));
	protected String userID;
	protected String roleID;
	protected String roleType;
	protected String loginName;
	protected String trueName;
	protected String loginTime;
	protected String loginType;
	protected String realname;
	protected String pmID;
	protected String instance;
	protected String userType;
	protected String accessToken;
	protected String ucenterToken;
	protected String queryPropbillendDate;

	public String getQueryPropbillendDate() {
		return queryPropbillendDate;
	}

	public void setQueryPropbillendDate(String queryPropbillendDate) {
		setValue("queryPropbillendDate",queryPropbillendDate);
		this.queryPropbillendDate = queryPropbillendDate;
	}



	public WebServiceSession() {
		

	}

	public WebServiceSession(String key, RedisClient rc) {
		this.rc = rc;
		this.key = key;

		if (rc.isExits(key)) {

			rc.setExpireSeconds(key, this.expireSeconds);
			this.getBaseInfo();
		}

	}

	public WebServiceSession(String key, RedisClient rc, Map<String, String> map) {

		this.rc = rc;
		this.key = key;
		this.setValue("accessToken", key);
		rc.setExpireSeconds(key, this.expireSeconds);

		if (map != null) {

			this.setValuesByMap(map);
		}
	}

	private void getBaseInfo() {

		Map<String, String> m = this.getValuesByFiles("userID", "loginName",
				"roleID", "trueName", "userType", "realname", "loginTime",
				"pmID", "instance", "loginType", "ucenterToken", "roleType","queryPropbillendDate");

		this.loginName = m.get("loginName");
		this.userID = m.get("userID");
		this.trueName = m.get("trueName");
		this.roleID = m.get("roleID");
		this.userType = m.get("userType");
		this.realname = m.get("realname");
		this.pmID = m.get("pmID");
		this.loginTime = m.get("loginTime");
		this.instance = m.get("instance");
		this.loginType = m.get("loginType");
		this.ucenterToken = m.get("ucenterToken");
		this.roleType = m.get("roleType");
		this.queryPropbillendDate=m.get("queryPropbillendDate");
	}

	public boolean remove(String key) {
		return rc.remove(key);

	}

	public void setValue(String key, String value) {

		rc.setValue(this.key, key, value);

	};

	public void setValuesByMap(Map<String, String> map) {
		rc.setValuesByMap(this.key, map);

	};

	public Map<String, String> getAllValues() {

		return rc.getAllValues(this.key);

	}

	public Map<String, String> getValuesByFiles(String... files) {

		return rc.getValuesByFiles2(this.key, files);
	}

	public String getKey() {
		return key;
	}

	@SuppressWarnings("unused")
	private void setKey(String key) {
		this.key = key;
	}

	public String getUserID() {
		return userID;
	}

	public void setUserID(String userID) {
		this.setValue("userID", userID);
		this.userID = userID;
	}

	public String getRoleID() {
		return roleID;
	}

	public void setRoleID(String roleID) {
		this.setValue("roleID", roleID);
		this.roleID = roleID;
	}

	public String getLoginName() {

		return loginName;
	}

	public void setLoginName(String loginName) {

		this.setValue("loginName", loginName);
		this.loginName = loginName;
	}

	public String getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(String loginTime) {
		this.setValue("loginTime", loginTime);
		this.loginTime = loginTime;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.setValue("realname", realname);
		this.realname = realname;
	}

	public String getPmID() {
		return pmID;
	}

	public void setPmID(String pmID) {
		this.setValue("pmID", pmID);
		this.pmID = pmID;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.setValue("userType", userType);
		this.userType = userType;
	}

	public String getAccessToken() {
		return accessToken;
	}

	public void setAccessToken(String accessToken) {
		this.setValue("accessToken", accessToken);
		this.accessToken = accessToken;
	}

	public String getTrueName() {
		return trueName;
	}

	public void setTrueName(String trueName) {
		this.setValue("trueName", trueName);
		this.trueName = trueName;
	}

	public int getExpireSeconds() {
		return expireSeconds;
	}

	public void setExpireSeconds(int expireSeconds) {
		this.expireSeconds = expireSeconds;
	}

	public String getInstance() {
		return instance;
	}

	public void setInstance(String instance) {
		this.setValue("instance", instance);
		this.instance = instance;
	}

	public String getLoginType() {
		return loginType;
	}

	public void setLoginType(String loginType) {
		this.setValue("loginType", loginType);
		this.loginType = loginType;
	}

	public String getUcenterToken() {
		return ucenterToken;
	}

	public void setUcenterToken(String ucenterToken) {
		this.setValue("ucenterToken", ucenterToken);
		this.ucenterToken = ucenterToken;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.setValue("roleType", roleType);

		this.roleType = roleType;
	}

}
